package searchteam.client.ui.widgets;

import searchteam.client.beansMirrors.PersonMirror;
import searchteam.client.beansMirrors.TeamMirror;
import searchteam.client.ui.handlers.LinkClickHandler;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Grid;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class TeamMirrorDisplay extends MirrorDisplay{
	
	private TeamMirror bean;
	private Display display;
	
	public TeamMirrorDisplay(Display d, TeamMirror mirror) {
		bean = mirror;
		display = d;
		this.setText(bean.getName());
	}
	
	public TeamMirror getBean() {
		return bean;
	}

	public Panel display() {
		
		Grid panel = new Grid(7, 2);
		
		Button buttonEdit = new Button("Modifier");
		buttonEdit.addClickHandler(new ClickHandler() {
			public void onClick(ClickEvent event) {
				new UpdateTeamPopUp(display, bean);
			}
		});
		
		Label chefLabel = new Label(bean.getTeamMaster().getName() + " " + bean.getTeamMaster().getFirstname());
		chefLabel.addClickHandler(new LinkClickHandler(display.getMainUI(), new PersonMirrorDisplay(display,bean.getTeamMaster())));
		
		VerticalPanel membersPanel = new VerticalPanel();
		
		panel.setWidget(0, 0, new Label("Nom : ") );
		panel.setWidget(0, 1, new Label(bean.getName()) );
		panel.setWidget(1, 0, new Label("Domaine : ") );
		panel.setWidget(1, 1, new Label(bean.getMeaning()) );
		panel.setWidget(2, 0, new Label("Statut : ") );
		panel.setWidget(2, 1, new Label(bean.getStatus()) );
		panel.setWidget(3, 0, new Label("Chef : ") );
		panel.setWidget(3, 1, chefLabel);
		panel.setWidget(4, 0, new Label("Membres : ") );
		panel.setWidget(4, 1, membersPanel);
		panel.setWidget(6, 1, buttonEdit);
		
		for(PersonMirror person : bean.getMembers()) {
			PersonMirrorDisplay p = new PersonMirrorDisplay(display, person);
			membersPanel.add(p);
			p.addClickHandler(new LinkClickHandler(display.getMainUI(), p));
		}
		
		return panel;
	}

	public int getId() {
		return bean.getId();
	}

}
